package com.huawei.appmarket.service.usercenter.userinfo.view.activity;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.fragment.LoadingFragment;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.framework.bean.operreport.ResultResponse;
import com.huawei.appmarket.service.usercenter.userinfo.bean.AddressBean;
import com.huawei.appmarket.service.usercenter.userinfo.bean.CountryInfo;
import com.huawei.appmarket.service.usercenter.userinfo.bean.CountryInfoQueryRes;
import com.huawei.appmarket.service.usercenter.userinfo.bean.UserInfoBean;
import com.huawei.appmarket.service.usercenter.userinfo.bean.UserInfoQueryRes;
import com.huawei.appmarket.service.usercenter.userinfo.view.widget.MobilePhoneChangeView;
import com.huawei.appmarket.service.usercenter.userinfo.view.widget.MobilePhoneChangeViewOverSea;
import com.huawei.appmarket.service.usercenter.userinfo.view.widget.ReceiverInfoAddView;
import com.huawei.appmarket.service.usercenter.userinfo.view.widget.ReceiverInfoAddViewOverSea;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import o.cks;
import o.cku;
import o.cvt;
import o.der.a;
import o.der.d;
import o.der.f;
import o.der.g;
import o.dgm;
import o.Logger;
import o.dof;
import o.emc;
import o.emd;
import o.eml;
import o.emn;
import o.eyo;
import o.FragmentTransaction;

public class InfoChangeActivity extends BaseActivity implements e, emn {
    private List<CountryInfo> ʻॱ;
    private String ʽॱ = "";
    private boolean ʾ = false;
    private MobilePhoneChangeViewOverSea ʿ;
    private MobilePhoneChangeView ˈ;
    private boolean ˉ;
    private boolean ˊˊ = false;
    private boolean ˊˋ = true;
    protected UserInfoBean ˊॱ;
    private boolean ˊᐝ = false;
    protected RelativeLayout ˋॱ;
    protected boolean ˏॱ = false;
    protected ReceiverInfoAddView ͺ;
    protected ReceiverInfoAddViewOverSea ॱˊ;
    private int ॱˋ = 0;
    protected RelativeLayout ॱˎ;
    private String ᐝॱ = "";

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().setBackgroundDrawableResource(a.ᐝ);
        setContentView(g.ʻॱ);
        Bundle extras = new SafeIntent(getIntent()).getExtras();
        if (extras != null) {
            this.ॱˋ = extras.getInt("changeKind", 0);
            this.ʾ = extras.getBoolean("fromWebView", false);
            this.ˊˋ = extras.getBoolean("is_china_area", true);
        }
        ᐝॱ();
        ॱ(this.ᐝॱ);
        ॱˊ();
        if (bundle == null) {
            ͺ();
            return;
        }
        this.ˊॱ = (UserInfoBean) bundle.getSerializable("userInfo");
        if (this.ˊॱ != null) {
            ᐝ();
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putSerializable("userInfo", this.ˊॱ);
        super.onSaveInstanceState(bundle);
    }

    private void ॱˊ() {
        this.ˋॱ = (RelativeLayout) findViewById(d.ˑॱ);
        this.ॱˎ = (RelativeLayout) findViewById(d.ˋﾞ);
        this.ˈ = (MobilePhoneChangeView) findViewById(d.ˊᶥ);
        this.ʿ = (MobilePhoneChangeViewOverSea) findViewById(d.ˊﾞ);
        this.ͺ = (ReceiverInfoAddView) findViewById(d.ˊʿ);
        this.ॱˊ = (ReceiverInfoAddViewOverSea) findViewById(d.ˊˑ);
    }

    private void ᐝॱ() {
        if (1 == this.ॱˋ) {
            this.ᐝॱ = getString(f.ꜞॱ);
        } else if (2 == this.ॱˋ) {
            this.ᐝॱ = getString(f.ﹶ);
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        String str;
        if (intent != null && 1123 == i2) {
            AddressBean addressBean = (AddressBean) intent.getParcelableExtra("addressprovinceSelect");
            AddressBean addressBean2 = (AddressBean) intent.getParcelableExtra("addresscitySelect");
            AddressBean addressBean3 = (AddressBean) intent.getParcelableExtra("addressdistrictSelect");
            if (addressBean != null) {
                str = addressBean.ˊ;
                if (addressBean2 != null) {
                    str = str + HwAccountConstants.BLANK + addressBean2.ˊ;
                }
                if (addressBean3 != null) {
                    str = str + HwAccountConstants.BLANK + addressBean3.ˊ;
                }
                if (this.ͺ != null) {
                    this.ͺ.setAreaInfo(str);
                }
                this.ʽॱ = str;
            }
        } else if (intent != null && 1126 == i2) {
            str = (String) intent.getSerializableExtra("selected_country_phone_info");
            String str2 = "";
            if (str == null) {
                str = str2;
            }
            if (this.ॱˊ.getVisibility() == 0) {
                this.ॱˊ.setCountryPhone(str);
            } else if (this.ʿ.getVisibility() == 0) {
                this.ʿ.setCountryPhone(str);
            }
        }
    }

    public boolean ˋ(TaskFragment taskFragment, b bVar) {
        if (ˋ(bVar)) {
            ResponseBean responseBean = bVar.ˋ;
            if (responseBean instanceof UserInfoQueryRes) {
                this.ˊˊ = true;
                UserInfoBean ॱ = ((UserInfoQueryRes) responseBean).ॱ();
                if (ॱ != null) {
                    this.ˊॱ = ॱ;
                }
                if (!(dof.ˋ(this.ʽॱ) || this.ˊॱ == null)) {
                    this.ˊॱ.ॱ(this.ʽॱ);
                }
            } else if (responseBean instanceof ResultResponse) {
                ॱ(responseBean);
            } else if (responseBean instanceof CountryInfoQueryRes) {
                this.ˊᐝ = true;
                this.ʻॱ = ((CountryInfoQueryRes) responseBean).ˋ();
            }
            if (this.ˊˋ) {
                if (this.ˊˊ) {
                    ᐝ();
                }
            } else if (this.ˊˊ && this.ˊᐝ) {
                ᐝ();
            }
            return true;
        }
        if (taskFragment instanceof LoadingFragment) {
            LoadingFragment loadingFragment = (LoadingFragment) taskFragment;
            eyo ॱ2 = eyo.ॱ(bVar.ˊ, bVar.ˋ, null);
            loadingFragment.ˏ(ॱ2.ˊ(), ॱ2.ᐝ());
        }
        return false;
    }

    private boolean ˋ(b bVar) {
        return bVar != null && bVar.ˋ != null && bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0;
    }

    private void ॱ(ResponseBean responseBean) {
        this.ˉ = responseBean.getRtnCode_() == 0;
        if (this.ˉ) {
            Toast.makeText(this, f.ᴵ, 0).show();
            if (this.ˊॱ != null) {
                ʼॱ();
            } else {
                Logger.ˏ("InfoChangeActivity", "completed bean null ");
            }
        } else {
            Toast.makeText(this, f.ᐝʼ, 0).show();
        }
        finish();
    }

    private void ʼॱ() {
        boolean z = true;
        if (1 == this.ॱˋ) {
            Intent intent = new Intent();
            intent.putExtra("phone", this.ˊॱ.ॱ());
            intent.putExtra("country_phone_code", this.ˊॱ.ʻ());
            setResult(-1, intent);
        } else if (2 == this.ॱˋ) {
            Intent intent2 = new Intent();
            String str = "has_addrss";
            if (dof.ˋ(this.ˊॱ.ˋ())) {
                z = false;
            }
            intent2.putExtra(str, z);
            setResult(-1, intent2);
        }
    }

    private void ˎ(boolean z) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putBoolean("submitSuccess", z);
        intent.putExtras(bundle);
        if (this.ॱˋ == 1) {
            setResult(1011, intent);
        } else if (this.ॱˋ == 2) {
            setResult(1012, intent);
        }
    }

    protected void ᐝ() {
        this.ˋॱ.setVisibility(8);
        this.ॱˎ.setVisibility(0);
        if (this.ॱˋ == 1) {
            if (this.ˊˋ) {
                this.ˈ.setVisibility(0);
                this.ˈ.setInterfaceAndUserInfo(this, this.ˊॱ);
                return;
            }
            this.ʿ.setVisibility(0);
            this.ʿ.setCountryInfoList(this.ʻॱ);
            this.ʿ.setInterfaceAndUserInfo(this, this.ˊॱ);
        } else if (this.ॱˋ != 2) {
        } else {
            if (this.ˊˋ) {
                this.ͺ.setVisibility(0);
                this.ͺ.setInterfaceAndUserInfo(this, this.ˊॱ);
                return;
            }
            this.ॱˊ.setVisibility(0);
            this.ॱˊ.setCountryInfoList(this.ʻॱ);
            this.ॱˊ.setInterfaceAndUserInfo(this, this.ˊॱ);
        }
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        cvt o_emc;
        cvt o_cvt = null;
        if (this.ˏॱ) {
            o_emc = new emc(this.ˊॱ);
        } else {
            o_emc = new eml();
            if (!this.ˊˋ) {
                o_cvt = new emd();
            }
        }
        o_emc.setServiceType_(dgm.ˎ(this));
        list.add(o_emc);
        if (o_cvt != null) {
            o_cvt.setServiceType_(dgm.ˎ(this));
            list.add(o_cvt);
        }
    }

    public void ˎ(UserInfoBean userInfoBean) {
        this.ˊॱ = userInfoBean;
        this.ˏॱ = true;
        ͺ();
    }

    protected void ͺ() {
        this.ˋॱ.setVisibility(0);
        this.ॱˎ.setVisibility(8);
        Fragment loadingFragment = new LoadingFragment();
        FragmentTransaction ˊ = ˏॱ().ˊ();
        ˊ.ˏ(d.ˑॱ, loadingFragment, "InfoGetLoadTag");
        ˊ.ˋ();
    }

    public void ˎ() {
        Serializable arrayList = new ArrayList();
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable("addresslist", arrayList);
        intent.putExtras(bundle);
        intent.setClass(this, AddressListActivity.class);
        try {
            startActivityForResult(intent, 1123);
        } catch (ActivityNotFoundException e) {
            Logger.ˋ("InfoChangeActivity", "ActivityNotFoundException :" + e.toString());
        }
    }

    public void aq_() {
        String str = "";
        if (this.ॱˊ.getVisibility() == 0) {
            str = this.ॱˊ.ͺ();
        } else if (this.ʿ.getVisibility() == 0) {
            str = this.ʿ.ˎ();
        }
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("country_phone_info_of_user", str);
        intent.putExtras(bundle);
        intent.setClass(this, ChooseCountryCommonActivity.class);
        try {
            startActivityForResult(intent, 1126);
        } catch (ActivityNotFoundException e) {
            Logger.ˋ("InfoChangeActivity", "ActivityNotFoundException :" + e.toString());
        }
    }

    public void finish() {
        if (this.ʾ) {
            ˎ(this.ˉ);
        }
        super.finish();
    }

    public void onBackPressed() {
        ˋˊ();
    }

    private void ˋˊ() {
        boolean z = false;
        if (this.ॱˋ == 1) {
            if (this.ˊˋ) {
                z = this.ˈ.ˋ();
            } else {
                z = this.ʿ.ʻ();
            }
        } else if (this.ॱˋ == 2) {
            if (this.ˊˋ) {
                z = this.ͺ.ˋॱ();
            } else {
                z = this.ॱˊ.ˋॱ();
            }
        }
        if (z) {
            cku ˏ = cku.ˏ(this, cku.class, null, getString(f.ﾟॱ));
            ˏ.ˎ(this);
            ˏ.ॱ(new cks(this) {
                final /* synthetic */ InfoChangeActivity ˏ;

                {
                    this.ˏ = r1;
                }

                public void enableNetworking() {
                    this.ˏ.finish();
                }

                public void upgrade() {
                }

                public void ˋ() {
                }
            });
            return;
        }
        super.onBackPressed();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        ˋˊ();
        return true;
    }
}
